package com.definesys.smecrailtransit.module.LineReport.adapter;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.base.SmecBaseRecyclerViewHolder;
import com.definesys.smecrailtransit.databinding.ItemLineReportFaultBinding;
import com.definesys.smecrailtransit.module.LineReport.bean.FaultStatisticsBean;

import java.util.ArrayList;

/**
 * Created by cjy on 2018/1/5.
 */

public class LineReportFaultAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder> {
    private ArrayList<FaultStatisticsBean> list;

    public LineReportFaultAdapter(){
        list = new ArrayList<>();
    }

    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemLineReportFaultBinding itemLineReportFaultBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_line_report_fault,parent,false);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new
                SmecBaseRecyclerViewHolder(itemLineReportFaultBinding.getRoot());
        smecBaseRecyclerViewHolder.setViewType(viewType);
        smecBaseRecyclerViewHolder.setBinding(itemLineReportFaultBinding);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        ItemLineReportFaultBinding itemLineReportFaultBinding = (ItemLineReportFaultBinding)holder.getBinding();
        itemLineReportFaultBinding.id.setText(list.get(position).getEleNo());
        itemLineReportFaultBinding.reason.setText(list.get(position).getFaultContent());
    }

    @Override
    public int getItemCount() {
        return this.list.size();
    }

    public ArrayList<FaultStatisticsBean> getList() {
        return list;
    }

    public void setList(ArrayList<FaultStatisticsBean> list) {
        if(list != null && list.size() !=0){
            this.list = list;
        }
    }
}
